<?php
namespace TestHome\Controller;
use Think\Controller;
class IndexController extends BaseController {

    public function index(){
        // 获取当前账户的登录信息
        $info = D('Users')
            ->relation(true)
            ->where(array('uid' => parent::$uid))->find();
        $info['lastdate'] = convertUnixTime($info['lastdate']);
        $info['sex'] = convertSex($info['sex']);
        $info['class_str'] = convertClassJson($info['orgnizer_info']['class']);
        $this->assign('userinfo', $info);
       // var_dump($info['class_str']);
        $this->display();
    }

    /**
     * 获得当前是否为组织者及用户名时间信息
     */


        public function isOrg()
    {
        if (M("orgnizers")->where(['uid' => parent::$uid])->select()){
            $this->ajaxReturn(["code" => 1]);
        }
        else
            $this->ajaxReturn(["code" => 0]);
    }

    public function getUserInfo()
    {

        $userinfo = M('users')->where(['uid' => parent::$uid])->find();

        $rs['username'] = $userinfo['username'];
        $rs['time'] = convertUnixTime(time());


        if (M("orgnizers")->where(['uid' => parent::$uid])->select()){
            $rs['is_org'] = 1;
        }
        else
            $rs['is_org'] = 0;

        $this->ajaxReturn($rs);
    }


    /**
     * 取得问卷进度
     */

    public function getQuizList()
    {
        //方法需要更新为添加一个quiz_status表，记录是否可见，完成度，是否被预警等信息

        $orgnizer_quiz_list = M("orgnizer_userquizlist")
            ->join("orgnizer_grouptest on orgnizer_grouptest.testgroup_id = orgnizer_userquizlist.testgroup_id")
            ->where(['uid' => parent::$uid])->select();


        //存在于组织者布置的测试当中
        if ($orgnizer_quiz_list){
            $quiz_list = json_decode($orgnizer_quiz_list[0]['quiz_list'], true);
            $oname = M('orgnizers')->where(['oid' => $orgnizer_quiz_list[0]['oid']])->select();
            $oname = $oname[0]['orgnizer_name'];
            $rs['orgnizer_name'] = $oname;
            $rs['orgnizer'] = 1;
            $rs['detail'] = D("User_answer")->QuizDetail($quiz_list, parent::$uid);

        }
        //用户单独做的测试
        else{
            $rs['orgnizer'] = 0;
        }

        $this->ajaxReturn($rs);

    }





}